package com.maven.demo.core.common;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

@SuppressWarnings("unchecked")
public class SpringBeanUtil implements BeanFactoryAware{
	private static BeanFactory bf;

	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		bf = beanFactory;
	}
	
	public static <T> T getBean(String BeanName) {
		if(null != bf) {
			return (T)bf.getBean(BeanName);
		}
		return null;
	}
	
	public static <T> T getBean(String BeanName,Class<?> clazz) {
		if(null != bf) {
			return (T)bf.getBean(BeanName,clazz);
		}
		return null;
	}
}
